package cn.szabadsag.hrm.config;

import org.springframework.context.annotation.Primary;
import org.springframework.stereotype.Component;
import springfox.documentation.swagger.web.SwaggerResource;
import springfox.documentation.swagger.web.SwaggerResourcesProvider;

import java.util.ArrayList;
import java.util.List;

@Component
@Primary
public class DocumentationConfig implements SwaggerResourcesProvider {
    @Override
    public List<SwaggerResource> get() {
        List resources = new ArrayList<>();
        /*正常来说只需要配置对应服务/v2/api-docs这个地址就好了，但是不能写死ip和端口
        http://localhost:4010/v2/api-docs*/

        //http://localhost:3010/services/sysmanage/v2/api-docs可以配置通过网关访问swagger地址，本来就在网关中配置，不需要写网关服务器地址。
        resources.add(swaggerResource("系统中心", "/services/sysmanage/v2/api-docs", "2.0"));
        resources.add(swaggerResource("授权中心", "/services/auth/v2/api-docs", "2.0"));
        resources.add(swaggerResource("公共服务", "/services/common/v2/api-docs", "2.0"));
        resources.add(swaggerResource("课程中心", "/services/course/v2/api-docs", "2.0"));
        resources.add(swaggerResource("搜索中心服务", "/services/search/v2/api-docs", "2.0"));
        resources.add(swaggerResource("用户中心服务", "/services/user/v2/api-docs", "2.0"));
        resources.add(swaggerResource("秒杀中心服务", "/services/kill/v2/api-docs", "2.0"));
        resources.add(swaggerResource("订单中心服务", "/services/order/v2/api-docs", "2.0"));
        return resources;

    }

    private SwaggerResource swaggerResource(String name, String location, String version) {
        SwaggerResource swaggerResource = new SwaggerResource();
        swaggerResource.setName(name);
        swaggerResource.setLocation(location);
        swaggerResource.setSwaggerVersion(version);
        return swaggerResource;
    }
}